 var date = ["2017-7-12","2017-7-13","2017-7-14","2017-7-15","2017-7-16","2017-7-17","2017-7-18","2017-7-19"];
 var data = [];
 for(var i = 0; i < 8; i++){
    var sum = parseInt(Math.random() * 9000 + 1000);
    data.push(sum);
 }
var sale_show = {
    el:"",
    init:function(el){
        this.el = el;
        this.saleEchart();
    },
    saleEchart:function(){
        // 基于准备好的dom，初始化echarts图表
        var myChart = echarts.init(document.getElementById(this.el)); 
        
        var option = {
            //标题组件
            title: {
                text: '本月订单数据',
                left: 'center',
                textStyle: {
                    color: '#999',
                    fontWeight:"bold",
                    fontSize:16
                }
            },
            //提示框组件
            tooltip: {
                trigger: 'axis'  //触发类型，坐标轴触发
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            //直角坐标系x轴
            xAxis: {
                type: 'category',  //类目轴  必须通过data是指类目数据
                boundaryGap:false,  //坐标两边留白政策，默认为true
                data:date
            },
            yAxis: {
                type: 'value',
                scale:true,  //是否脱离0比值，只在type:"value"中有效  设置为true坐标轴不会强制包含0刻度
                name:"订单数",
                splitLine: {
                    show: false
                },
                min:0
            },
            textStyle: {
                color: '#838FA1'
            },
            //系列列表
            series: [
            {
                name: '本月订单数据',
                type: 'line',
                itemStyle:{
                    normal:{
                        color:"#3693fc"
                    }
                },
                lineStyle:{
                    normal:{
                        color:"#3693fc"
                    }
                },
                // areaStyle: {normal: {
                //     color:"rgba(227,239,253,1)"
                // }},
                data: data
            }
            ]
        };

        myChart.setOption(option);
    }
};

//图表显示
var terminal_show = {
    el:"",
    init:function(el){
        this.el = el;
        // this.getHeight();
        this.terminal_show();
    },
    getHeight:function(){
        $(".widget").css("margin",0);
        var height1 = $(window).height() - $(".widget-head").height() - parseInt($(".widget").css("padding-top")) - parseInt($(".widget").css("padding-bottom")) - 60;
        console.log($(".widget").css("padding"));
        $("#"+this.el+"").height(height1);
    },
    terminal_show:function(){
        var myChart = echarts.init(document.getElementById(this.el));
        var option_pie = null;
        options_pie = {
            title : {
                text: '用户终端类型',
                left: 'center',
                textStyle: {
                    color: '#999',
                    fontWeight:"bold",
                    fontSize:16
                }
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['unkown','STB','PC','Android Phone','Android Pad','iOS Phone','iOS Pad','Web'],
                textStyle: {
                    color: '#838FA1'
                }
            },
            color:['#58b1f9','#7fc4fc','#cde2fa','#5dc485','#88d9a0','#b5ebc5','#ffe167','#ffb59b'],
            // color:['#58b1f9','#5dc485','#f2686a','#c7ddf6','#f5c162','#00d2b5','#dda669','#4c9ad5'],
            animate:true,
            series : [
                {
                    name: '终端类型',
                    type: 'pie',
                    radius : '55%',
                    center: ['50%', '60%'],
                    data:[
                        {value:335, name:'unkown'},
                        {value:310, name:'STB'},
                        {value:155, name:'PC'},
                        {value:135, name:'Android Phone'},
                        {value:121, name:'Android Pad'},
                        {value:107, name:'iOS Phone'},
                        {value:77, name:'iOS Pad'},
                        {value:56, name:'Web'}
                    ],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        myChart.setOption(options_pie, true);
    }
};

// 调用echarts
sale_show.init("sale_echarts");
terminal_show.init("terminal_echarts");
sale_show.init("user_echarts");


//绑定radio的改变监听事件
    var radio_monitor = {
        el:"",  //需要改变的值
        init:function(options){
            this.el = options.el;
            this.filterShow();
            this.loadMonitor();
            this.changeMonitor();
        },
        //指标筛选显示
        filterShow:function(){
            $(".widget-index-filter .flash-indicator").find("a").on("click",function(){
                if($(".flash-indicator-container").css("display") == "none"){
                    $(".widget-index-filter .flash-indicator-container").css("display","block");
                    $(this).parent(".flash-indicator").find("i").removeClass("am-icon-angle-down").addClass('am-icon-angle-up').addClass("filter-show");
                }else if($(".flash-indicator-container").css("display") == "block"){
                    $(".widget-index-filter .flash-indicator-container").css("display","none");
                    $(this).parent(".flash-indicator").find("i").removeClass("am-icon-angle-up").removeClass("filter-show").addClass('am-icon-angle-down');
                }
            })
            $(".widget-index-filter .flash-indicator").find("i").on("click",function(){
                if($(".flash-indicator-container").css("display") == "none"){
                    $(this).parent("div").siblings(".flash-indicator-container").css("display","block");
                    $(this).removeClass("am-icon-angle-down").addClass('am-icon-angle-up').addClass("filter-show");
                }else if($(".flash-indicator-container").css("display") == "block"){
                    $(this).parent("div").siblings(".flash-indicator-container").css("display","none");
                    $(this).removeClass("am-icon-angle-up").removeClass("filter-show").addClass('am-icon-angle-down');
                }
            })
        },
        //加载初始化
        loadMonitor:function(){
            $(this.el).attr("title",$("input[type='radio']:checked").parent("label").attr("title"));
            $(this.el).text($("input[type='radio']:checked").parent("label").attr("title"));
        },
        //改变radio选中
        changeMonitor:function(){
            var that = this;
            $(":radio").on("click",function(){
                $(that.el).attr("title",$(this).parent("label").attr("title"));
                $(that.el).text($(this).parent("label").attr("title"));
            })
        }
    }
    radio_monitor.init({
        "el":"#index_checked"
    });